package com.edu.juc.completableFuture.completionStage;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

public class APITest4 {
    public static void main(String[] args) {
        CompletableFuture<Integer> task1 = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return 1;
        });

        CompletableFuture<Integer> task2 = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e){
                throw new RuntimeException(e);
            }
            return 2;
        });

        CompletableFuture<Integer> task = task1.thenCombine(task2, Integer::sum);
        System.out.println(task.join());
    }
}
